/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Interpreter.Function.Time;

import Interpreter.Function.Function;
import Interpreter.InterpreterVisitor;
import ast.AST;
import java.text.*;
import java.util.*;

/**
 *
 * @author David
 */
public class BeforeFunction extends Function{
    
    @Override
    public Object execute(ArrayList args) {

 
        SimpleDateFormat dateFormat = new SimpleDateFormat("EEE MMM dd kk:mm:ss z yyyy");
        
        try{
            
            Date firstDate = dateFormat.parse(((AST)args.get(0)).accept(new InterpreterVisitor()).toString());
            Date secondDate = dateFormat.parse(((AST)args.get(1)).accept(new InterpreterVisitor()).toString());
            
            if(firstDate.before(secondDate)) {
                return true;
            }
            else {
                return false;
            }

        } catch (Exception e) { 
            System.out.println(e.toString());
            /*There was probably an error in the parsing!*/
        }

        return null;
    }
}
